package com.alatus.ai.app;

import org.springframework.ai.image.Image;
import org.springframework.ai.image.ImagePrompt;
import org.springframework.ai.image.ImageResponse;
import org.springframework.ai.openai.OpenAiImageClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OpenAiImageController {
    @Autowired
    private OpenAiImageClient openAiImageClient;
    @GetMapping(value = "/image",produces = "text/html")
    public String createImage(String prompt) {
        ImageResponse imageResponse = openAiImageClient.call(new ImagePrompt(prompt));
        Image output = imageResponse.getResult().getOutput();
//        图片的URL地址
        String url = output.getUrl();
//        图片的Base64编码
        String b64Json = output.getB64Json();
        return "<img src="+url+"/>";
    }
}
